<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="js/http.js"></script>
  <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
  <p class="bar">
    <label >导航栏</label>
    <span onclick="location.href='login.html'">登录页</span>
    <span onclick="location.href='register.html'">注册页</span>
    <span onclick="location.href='welcome.html'">欢迎页</span>
  </p>
  登录成功
  当前用户：<span id="user-name"></span>
</body>
<script>
function getCookie(name){
  var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  if(arr=document.cookie.match(reg)){
    return unescape(arr[2]);
  } else {
    return null;
  }
}
let token = getCookie('sc-token')
ajax(`/api/user/info/${token}`,(res)=>{
  if(res.indexOf('<span class="btn" onclick="login()">登录</span>')>0){
    location.href = 'login.html'
  }
  document.getElementById('user-name').innerHTML = res
},(res)=>{
  alert(res)
})
</script>
</html>